
from whiff import resolver
from whiff.resources import sessionDirectory
import resumes

def application():
    "configure resumes application root to have sessions and profiles in the tmp directory"
    app = resolver.moduleRootApplication("/", resumes)
    mkdir("/tmp/sessions")
    # set sessions resources to have a one hour timeout
    sessions = sessionDirectory.directorySessionFinder("/tmp/sessions", timeout=60*60)
    app.registerResourceFinder(prefix="session", finder=sessions)
    mkdir("/tmp/profiles")
    profiles = sessionDirectory.directoryProfileFinder("/tmp/profiles")
    app.registerResourceFinder(prefix="profile", finder=profiles)
    return app

def mkdir(directory):
    import os
    if not os.path.exists(directory):
        os.mkdir(directory)
        os.chmod(directory, int("777", 8))

if __name__=="__main__":
    import wsgiref.simple_server
    print "serving wsgi at 8888"
    testapp = application()
    srv = wsgiref.simple_server.make_server('localhost', 8888, testapp)
    srv.serve_forever()
